package mymvc.ui
{
	 /**
	 * 
	 * 控制子弹的行为
	 * 
	 * 
	 * 
	 */ 
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.filters.DisplacementMapFilter;
	
	import mymvc.event.BulletLeaveBorderEvent;
	
	public class BulletBehaviour
	{
		public var vy:int = 3;
		private var bullet:DisplayObject = null;
		private var isShoot:Boolean = false;
		public function BulletBehaviour(bullet:DisplayObject)
		{
			this.bullet = bullet;
		}
		
		public function moving():void{
			if(isShoot)
				return ;
			bullet.parent.stage.addEventListener(Event.ENTER_FRAME,onEnterFrame)
			isShoot = true;
		}
		
		public function stopMoving():void{
			bullet.parent.stage.removeEventListener(Event.ENTER_FRAME,onEnterFrame)	
		}
		
		public function onEnterFrame(event:Event):void{
			if(bullet.y + bullet.height <= 0 ){
				bullet.visible = 0;
			}
			bullet.y -= vy; 
			if(bullet.y<0){
				bullet.parent.stage.removeEventListener(Event.ENTER_FRAME,onEnterFrame)
				bullet.dispatchEvent(new 
					BulletLeaveBorderEvent(BulletLeaveBorderEvent.BULLET_LEAVE_BORDER));
			}
		}
	}
}